using System;
using System.Collections.Generic;
using System.Text;

using SD.LLBLGen.Pro.ORMSupportClasses;
using DatabaseAdapter;
using DatabaseGeneric;
using DatabaseGeneric.FactoryClasses;
using DatabaseGeneric.EntityClasses;
using DatabaseGeneric.RelationClasses;
using DatabaseGeneric.HelperClasses;

namespace Services
{
    public class SanPhamBo : Interfaces.ISanPhamBo
    {
        public EntityCollection<SanPhamBoEntity> FetchCollection()
        {
            EntityCollection<SanPhamBoEntity> collectionSanPhamBo = new EntityCollection<SanPhamBoEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamBo, null);
            }
            return collectionSanPhamBo;
        }

        public EntityCollection<SanPhamBoEntity> FetchCollection(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            EntityCollection<SanPhamBoEntity> collectionSanPhamBo = new EntityCollection<SanPhamBoEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamBo, new RelationPredicateBucket(SanPhamBoFields.MaChungLoaiSanPham == currentEntityChungLoaiSanPham.MaChungLoaiSanPham));
            }
            return collectionSanPhamBo;
        }

        public EntityCollection<SanPhamBoEntity> FetchCollection(string criteria, int option)
        {
            EntityCollection<SanPhamBoEntity> collectionSanPhamBo = new EntityCollection<SanPhamBoEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                switch (option)
                {
                    case 1:
                        adapter.FetchEntityCollection(collectionSanPhamBo, new RelationPredicateBucket(SanPhamBoFields.MaChungLoaiBo == criteria));
                        break;
                }
            }
            return collectionSanPhamBo;
        }

        public SanPhamBoEntity FetchEntity(SanPhamBoEntity currentEntitySanPhamBo)
        {
            SanPhamBoEntity entitySanPhamBo = new SanPhamBoEntity(currentEntitySanPhamBo.MaSanPhamBo);
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(entitySanPhamBo);
            }
            return entitySanPhamBo;
        }

        public int SaveCollection(EntityCollection<SanPhamBoEntity> currentCollectionSanPhamBo)
        {
            int cntSave = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                cntSave = adapter.SaveEntityCollection(currentCollectionSanPhamBo);
            }
            return cntSave;
        }

        public bool SaveEntity(SanPhamBoEntity currentEntitySanPhamBo)
        {
            bool isSave = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isSave = adapter.SaveEntity(currentEntitySanPhamBo);
            }
            return isSave;
        }

        public int DeleteCollection(EntityCollection<SanPhamBoEntity> currentCollectionSanPhamBo)
        {
            int cntDelete = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.DeleteEntityCollection(currentCollectionSanPhamBo);
            }
            return cntDelete;
        }

        public bool DeleteEntity(SanPhamBoEntity currentEntitySanPhamBo)
        {
            bool isDelete = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isDelete = adapter.DeleteEntity(currentEntitySanPhamBo);
            }
            return isDelete;
        }

        public System.Data.DataTable Report(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            System.Data.DataTable dtSanPhamBo = new System.Data.DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                dtSanPhamBo = RetrievalProcedures.SanPhamBoByChungLoaiSanPhamPro(currentEntityChungLoaiSanPham.MaChungLoaiSanPham, adapter);
            }
            return dtSanPhamBo;
        }
    }
}
